new_element = document.createElement("script");
new_element.setAttribute("type", "text/javascript");
new_element.setAttribute("src", "/view/app/user/js/md5.js");
document.body.appendChild(new_element);

regular = document.createElement("script");
regular.setAttribute("type", "text/javascript");
regular.setAttribute("src", "/view/resources/js/utils/Regular.js");
document.body.appendChild(regular);

stringUntil = document.createElement("script");
stringUntil.setAttribute("type", "text/javascript");
stringUntil.setAttribute("src", "/view/resources/js/utils/stringUtil.js");
document.body.appendChild(stringUntil);

function loginClick() {
    var name = document.getElementById("name").value;
    var password = document.getElementById("password").value;

    //去空格
    name = trim(name);
    password = trim(password);

    //判断合法性
    if (name == null || password == null || name == "" || password == "") {
        alert("输入不能为空");
        return;
    }


    document.getElementById("password").value = hex_md5(password);

    document.getElementById("login").submit();

}

function resgister() {
    var name = document.getElementById("name").value;
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;
    var ispassword = document.getElementById("isPassword").value;

    //去空格
    name = trim(name);
    email = trim(email);
    password = trim(password);
    ispassword = trim(ispassword);

    if (name == null || email == null || password == null || ispassword == null
        || name == "" || email == "" || password == "" || ispassword == "") {
        alert("输入不能有为空的项");
        return;
    }

    if (password != ispassword) {
        alert("你两次输入的密码不相同，请重新输入！");
        return;
    }

    if (name == password) {
        alert("账号和密码不允许相同！");
        return;
    }

    //验证邮箱是否是邮箱
    if (!isEmail(email)) {
        alert("你输入的不是邮箱！请输入正确的邮箱，以保证以后方便与您联系。");
        return;
    }
    //验证密码强度够不够
    if (password.length < 7) {
        alert("密码太短了，密码长度请大于6个字符，不支持空格字符！")
    }

    document.getElementById("isPassword").value = hex_md5(ispassword);
    document.getElementById("password").value = hex_md5(password);

    document.getElementById("register").submit();
}


function resetPassword() {
    var password = document.getElementById("password").value;
    var isPassword = document.getElementById("isPassword").value;
    var isReset = document.getElementById("isReset").value;

    password = trim(password);
    isPassword = trim(isPassword);
    isReset = trim(isReset);

    if (isReset != "reset") {
        alert("请先申请验证码！");
        return;
    }

    if (password == "", isPassword == "") {
        alert("输入不能为空！");
        return;
    }

    if (password != isPassword) {
        alert("两次输入的密码不同，请重新输入！");
        return;
    }

    document.getElementById("password").value = hex_md5(password);
    document.getElementById("isPassword").value = hex_md5(isPassword);
    document.getElementById("reset").submit();
}

function JumpVerification() {
    var email = document.getElementById("email").value;
    var verification = document.getElementById("verification").value;
    var trueValue = document.getElementById("trueValue").value;
    var isVerification = document.getElementById("isVerification").value;


    email = trim(email);
    verification = trim(verification);
    trueValue = trim(trueValue);
    isVerification = trim(isVerification);

    if (isVerification != "verification") {
        alert("请从申请验证码页面进入！");
        return;
    }

    if (email == "") {
        alert("请输入你的邮箱！");
        return;
    }

    if (!isEmail(email)) {
        alert("你输入的不是邮箱，请你确认你的邮箱是否输入正确！");
        return;
    }

    //不为空说明已经申请了验证码
    if (trueValue != "") {
        if (verification == "") {
            alert("请输入你收到的验证码！");
            return;
        }
        verification = hex_md5(verification);

        if (verification == trueValue) {
            var url = "/view/app/user/resetpassword.jsp";
            jump(url);
        } else {
            alert("你输入的验证码错误！请重新输入验证码");
        }
    } else {
        document.getElementById("fromVerification").submit();
    }


}

function jump(url) {
    location.href = url;
}

String.prototype.trim = function () {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}